/**
 * 
 */
package net.phoenix.repository.query.lucene;

import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.query.Row;

import org.apache.lucene.document.Document;

/**
 * @author lixf
 *
 */
public class LuceneRow implements Row,Constants {
	private Document row;
	private ValueFactory factory ;
	private Session session;
	public LuceneRow(Session session, Document row) throws UnsupportedRepositoryOperationException, RepositoryException{
		this.row = row;
		this.session = session;
		this.factory = session.getValueFactory();
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getValues()
	 */
	@Override
	public Value[] getValues() throws RepositoryException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getValue(java.lang.String)
	 */
	@Override
	public Value getValue(String columnName) throws ItemNotFoundException, RepositoryException {
		return factory.createValue(row.get(columnName));
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getNode()
	 */
	@Override
	public Node getNode() throws RepositoryException {
		String pkid = row.get(INDEX_IDENTIFIER);
		return session.getNodeByIdentifier(pkid);
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getNode(java.lang.String)
	 */
	@Override
	public Node getNode(String selectorName) throws RepositoryException {		
		return this.getNode();
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getPath()
	 */
	@Override
	public String getPath() throws RepositoryException {
		return this.row.get(INDEX_PATH);
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getPath(java.lang.String)
	 */
	@Override
	public String getPath(String selectorName) throws RepositoryException {		
		return this.getPath();
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getScore()
	 */
	@Override
	public double getScore() throws RepositoryException {	
		return 0.0;
	}

	/* (non-Javadoc)
	 * @see javax.jcr.query.Row#getScore(java.lang.String)
	 */
	@Override
	public double getScore(String selectorName) throws RepositoryException {		
		return getScore();
	}

}
